<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp"%>
<%@ include file="/WEB-INF/pages/common/back-common.jsp"%>
<%@ include file="/WEB-INF/pages/common/jquery2.1.4.jsp"%>
<%@ include file="/WEB-INF/pages/common/back-dialog.jsp"%>
<html>
    <head>
        <title>创建</title>
         <script type='text/javascript' src="<ls:templateResource item='/resources/common/js/jquery.validate.js'/>"></script>
         <link rel="stylesheet" type="text/css" media="screen" href="${contextPath}/resources/common/css/errorform.css" />
		 <link href="<ls:templateResource item='/resources/plugins/select2-4.0/select2.css'/>" rel="stylesheet"/>
		 <script src="<ls:templateResource item='/resources/plugins/select2-4.0/select2.full.min.js'/>" type="text/javascript"></script>
		 <script src="<ls:templateResource item='/resources/plugins/select2-4.0/i18n/zh-CN.js'/>" type="text/javascript"></script>
		 <script src="<ls:templateResource item='/resources/plugins/select2-4.0/makeSelect2.js'/>" type="text/javascript"></script>
        <script language="javascript">
            $.validator.setDefaults({
            });
            var  contextPath = '${contextPath}';
            $(document).ready(function() {
                jQuery("#form1").validate({
                    rules: {
                        userName: {
                            required: true,
                        }
                    },
                    messages: {
                        userName: {
                            required: "请选择组员"
                        }
                    }
                });

                makeSelect2(contextPath + "/admin/adminUser/userListForTeam/${projectId}","select[name=\'userName\']","项目成员","value","key");

                //binding Submit
                $("#Submit").click(function(){
                    if($("#form1").valid()){
                        var formData = $("#form1").serialize();
                        $.ajax({
                            type: 'post', // 提交方式 get/post
                            url:  "${contextPath}/admin/projectMember/saveBatch", // 需要提交的 url
                            data: formData,
                            dataType : 'json',
                            error: function(jqXHR, textStatus, errorThrown) {
                                alert("保存失败" + textStatus);
                            },
                            success: function(data) { // data 保存提交后返回的数据，一般为 json 数据
                                console.log(data)
                                // 此处可对 data 作相关处理
                                if("success" == data){
                                    layer.msg("保存成功");
                                    closeDialog();
                                }else{
                                    layer.msg("保存失败");
                                }

                            }
                        });
                        return false; // 阻止表单自动提交事件
                    };
                });


            });

            function closeDialog(){
                var index = parent.layer.getFrameIndex("updateProjectMemberBatch"); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
                if(parent.sendData){
                    parent.sendData();//异步
                }else{
                    parent.location.reload();
                }
            }
        </script>
    </head>
    <body>
        <form action="<ls:url address='/admin/projectMember/saveBatch'/>" method="post" id="form1">
            <input id="id" name="id" value="${projectMember.id}" type="hidden">
            <input id="projectId" name="projectId" value="${projectId}" type="hidden">
            <table border="0" align="center" class="${tableclass}" id="col1" style="width: 600px">
                <thead>
                    <tr class="sortable">
                        <th colspan="3">
                            <div align="center">
                                	批量创建项目成员
                            </div>
                        </th>
                    </tr>
                </thead>
             <tr>
                    <td style="align-content: center">顺序</td>
                    <td>选择组员: <font color="ff0000">*</font></td>
                    <td>选择职位</td>
             </tr>
                <c:forEach items="${projectMembers}"  var="projectMember" varStatus="status">
                    <tr>
                        <td>${status.index +1}</td>
                        <td>
                            <select name="userName" style="width: 200px;">
                                <c:if test="${not empty projectMember.userName}">
                                    <option value="${projectMember.userName}">${projectMember.userRealName}</option>
                                </c:if>
                            </select>
                        </td>
                        <td>
                            <select name="roleId"  class="${selectclass}">
                                <ls:optionGroup type="select" required="false" cache="true" beanName="STAFF_POSITION" selectedValue="${projectMember.roleId}"/>
                            </select>
                        </td>
                    </tr>

                </c:forEach>

                <%
                    Integer count = (Integer)request.getAttribute("count");
                    Integer end;
                    if(count < 12){ //一个页面建议最多只有12个
                        end = 12;
                    }else{
                        end = count + 4; //每次多4个
                    }
                    for (int i = count; i < end; i++) {
                %>

                   <tr>
                       <td><%=i + 1%></td>
                       <td>
                           <select name="userName"  style="width: 200px;">

                           </select>
                       </td>
                       <td>
                           <select name="roleId"  class="${selectclass}">
                               <ls:optionGroup type="select" required="false" cache="true"
                                               beanName="STAFF_POSITION" selectedValue="${projectMember.roleId}"/>
                           </select>
                       </td>
                   </tr>
                <% } %>

               <tr>
                    <td colspan="3">
                        <div align="center">
                            <input type="button" name="Submit" id="Submit"  value="提交" />
                            <input type="button" value="关闭" onclick="javascript:closeDialog()" />
                        </div>
                    </td>
                </tr>
            </table>
        </form>

    </body>
</html>

